#ifndef SYNTAX_ERROR_H
#define SYNTAX_ERROR_H

#pragma once

#include "antlr4-runtime.h"
#include "macros.h"
#include "json.hpp"

namespace cyclone::parser
{
    using antlr4::Parser;
    using antlr4::RecognitionException;

    struct SourceCodeLocation
    {
        size_t line = 0;
        size_t column = 0;
    };
    NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SourceCodeLocation, line, column);
    class SyntaxError : public RecognitionException
    {
    public:
        SyntaxError(Parser *recognizer);
        SyntaxError(Parser *recognizer, const std::string &msg);
        SyntaxError(Parser *recognizer, const std::string &msg, const SourceCodeLocation &loc);
        SyntaxError(const RecognitionException &ex);
        SyntaxError(SyntaxError const &) = default;
        SyntaxError &operator=(SyntaxError const &) = default;
        ~SyntaxError();

        /**
         * NOTE All three kind exception of the antlr builtin exceptions are handled here
         */
        static void handleNonSemanticError(Parser *);
        SourceCodeLocation location;
        std::string message;
    };
    NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyntaxError, message, location);

} // namespace cyclone::parser

#endif